package com.kaibes.imserver.model;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Set;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.kaibes.imserver.KaibesIMServer;
import com.kaibes.imserver.control.UserSocketControl;
import com.kaibes.imserver.control.threads.ClientStringReader;
import com.kaibes.imserver.model.data.ContactsInformationsData;
import com.kaibes.imserver.model.data.KaibesFile;
import com.kaibes.imserver.model.data.UserCenterInformationData;
import com.kaibes.imserver.model.data.UserinformationData;
import com.kaibes.imserver.model.database.KaibesimcenterHelper;
import com.kaibes.imserver.model.database.UsercenterHelper;
import com.kaibes.imserver.model.utils.ByteStringUtil;
import com.kaibes.imserver.model.utils.JsonParserUtil;
import com.kaibes.imserver.model.utils.StaticValuesUtil;
import com.kaibes.imserver.view.ServerMainView;

public class ActionReaderCallback {

	private ActionReaderCallback() {
	}

	public static int parsingDataLogin(UserSocketControl userSocketControl,
			String json) {
		JsonParserUtil jsonParserUtil = new JsonParserUtil();
		int goInt = ClientStringReader.continueInt;
		Integer head = null;
		Integer action = null;

		if (jsonParserUtil.parserJsonString(json) != null
				&& (head = (Integer) jsonParserUtil.getValue("h")) != null
				&& (action = (Integer) jsonParserUtil.getValue("a")) != null
				&& jsonParserUtil.setJsonArraySon("d") != null) {

			if (head == 1) {

				switch (action) {
					case 0:
					// TODO
					break;

					case 1: {
						ServerMainView.serverPanelView.panel_main
								.addLog(jsonParserUtil.toString());

						String username = (String) jsonParserUtil
								.getJsonObjectSonValue("username");
						String password = (String) jsonParserUtil
								.getJsonObjectSonValue("password");
						String question = (String) jsonParserUtil
								.getJsonObjectSonValue("question");
						String answer = (String) jsonParserUtil
								.getJsonObjectSonValue("answer");

						int i = UsercenterHelper.getInstance()
								.insertUserinformation(username, password,
										question, answer);

						jsonParserUtil.newSelf(head, action);

						if (i > 0) {
							jsonParserUtil
									.putJsonObjectSonValue("result", true);
							jsonParserUtil.putJsonObjectSonValue("message",
									"恭喜注册用户" + username + "成功！");
						} else {
							jsonParserUtil.putJsonObjectSonValue("result",
									false);
							jsonParserUtil.putJsonObjectSonValue("message",
									"该用户名已经存在!");
						}
						jsonParserUtil.commit(userSocketControl
								.getClientStringWriter());
					}
					break;

					case 2:
					break;

					case 3: {
						goInt = ClientStringReader.continueInt;
						ServerMainView.serverPanelView.panel_main
								.addLog(jsonParserUtil.toString());

						String username = (String) jsonParserUtil
								.getJsonObjectSonValue("username");
						String password = (String) jsonParserUtil
								.getJsonObjectSonValue("password");

						UserCenterInformationData userinfoData = new UserCenterInformationData(
								UsercenterHelper.getInstance()
										.getUserinformationResultSet(username));

						jsonParserUtil.newSelf(head, action);
						if (KaibesIMServer.mainClientControl
								.getMainSocketControl(username) != null) {
							jsonParserUtil.putJsonObjectSonValue("result",
									false).putJsonObjectSonValue("message",
									"该用户已经登陆！！");
						} else if (userinfoData.getUsername() == null) {
							jsonParserUtil.putJsonObjectSonValue("result",
									false).putJsonObjectSonValue("message",
									"用户名输入不正确！");
						} else {
							if (userinfoData.getPassword().equals(password)) {
								ServerMainView.serverPanelView.panel_login
										.addLog("ActionCallbackModel" + ": "
												+ userinfoData.getUsername()
												+ "用户登录验证成功！！!");
								userSocketControl
										.setUserCenterData(userinfoData);
								KaibesIMServer.mainClientControl
										.putMainSocketControl(username,
												userSocketControl);

								KaibesIMServer.mainClientControl
										.removeLoginSocketControl(userSocketControl
												.getClient()
												.getRemoteSocketAddress()
												.toString());

								// 登陸成功，開啟監聽線程
								userSocketControl.createThreadMain(1);

								jsonParserUtil.putJsonObjectSonValue("result",
										true).putJsonObjectSonValue("message",
										"登陆成功！正在跳转进主界面。。。");
								goInt = ClientStringReader.breakInt;
							} else {
								jsonParserUtil.putJsonObjectSonValue("result",
										false).putJsonObjectSonValue("message",
										"密码输入不正确！");
							}
						}
						jsonParserUtil.commit(userSocketControl
								.getClientStringWriter());
					}
					break;

					default:
					break;
				}
			}
		} else {
			ServerMainView.serverPanelView.panel_login.addLog("发现非法链接，抛弃掉！");
			return ClientStringReader.stopInt;
		}

		return goInt;
	}

	public static int parsingDataMain(UserSocketControl userSocketControl,
			String json) {
		JsonParserUtil jsonParserUtil = new JsonParserUtil();
		int goInt = ClientStringReader.continueInt;
		Integer head = null;
		Integer action = null;

		if (jsonParserUtil.parserJsonString(json) != null
				&& (head = (Integer) jsonParserUtil.getValue("h")) != null) {

			if (head == 1
					&& ((action = (Integer) jsonParserUtil.getValue("a")) != null)
					&& jsonParserUtil.setJsonArraySon("d") != null) {

				switch (action) {
					case 4: {
						UserinformationData userinformationData = new UserinformationData(
								KaibesimcenterHelper.getInstance()
										.getUserinformation(
												userSocketControl
														.getUserCenterData()
														.getUsername()));

						jsonParserUtil
								.newSelf(head, action)
								.putJsonArraySonValue(
										userinformationData.getJSONObject())
								.commitNotJSONObjectSon(
										userSocketControl
												.getClientStringWriter());

						// 获取通知
						jsonParserUtil.newSelf(head,
								NotificationInterpreter.ACTION);
						ResultSet result_notification = KaibesimcenterHelper
								.getInstance().getNotificationByUsername(
										userSocketControl.getUserCenterData()
												.getUsername());

						if (result_notification != null) {
							try {
								while (result_notification.next()) {
									int notification_id = result_notification
											.getInt("id");
									int notification_action = result_notification
											.getInt("action");
									if (notification_action == 1) {
										KaibesimcenterHelper.getInstance()
												.removeNotification(
														notification_id);
									}
									jsonParserUtil
											.putJsonObjectSonValue("id",
													notification_id)
											.putJsonObjectSonValue("action",
													notification_action)
											.putJsonObjectSonValue(
													"contactname",
													result_notification
															.getString("contactname"))
											.putJsonObjectSonValue(
													"message",
													result_notification
															.getString("message"))
											.addJSONObjectSon()
											.newJsonObjectSon();
								}
								jsonParserUtil
										.commitNotJSONObjectSon(userSocketControl
												.getClientStringWriter());
							} catch (JSONException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							} catch (SQLException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}
						}

						goInt = ClientStringReader.continueInt;
					}
					break;

					case 5: {
						JsonParserUtil jsonParserUtil2 = new JsonParserUtil(
								head, action);

						if (jsonParserUtil.getJsonObjectSonValue("contactname") != null) {
							for (int i = 0; i < jsonParserUtil
									.getJsonArraySon().length(); i++) {
								setOnline((String) jsonParserUtil
										.setJsonObjectSon(i)
										.getJsonObjectSonValue("contactname"),
										userSocketControl, jsonParserUtil2);
							}

						} else {
							ResultSet result = KaibesimcenterHelper
									.getInstance().getContactname(
											userSocketControl
													.getUserCenterData()
													.getUsername());

							if (result != null) {
								try {
									while (result.next()) {
										setOnline(
												result.getString("contactname"),
												userSocketControl,
												jsonParserUtil2);
									}

								} catch (SQLException e) {
									e.printStackTrace();
								}
							}
						}

						jsonParserUtil2
								.commitNotJSONObjectSon(userSocketControl
										.getClientStringWriter());

						goInt = ClientStringReader.continueInt;
					}
					break;

					case 6: {
						String to = (String) jsonParserUtil
								.getJsonObjectSonValue("to");
						String message = (String) jsonParserUtil
								.getJsonObjectSonValue("message");

						UserSocketControl toClient = null;

						if ((toClient = KaibesIMServer.mainClientControl
								.getMainSocketControl(to)) != null) {
							jsonParserUtil
									.newSelf(head, action)
									.putJsonObjectSonValue(
											"from",
											userSocketControl
													.getUserCenterData()
													.getUsername())
									.putJsonObjectSonValue("message", message)
									.commit(toClient.getClientStringWriter());
						} else {
							System.err.println(jsonParserUtil.toString());
						}
						goInt = ClientStringReader.continueInt;
					}
					break;

					case 7:
					break;

					case 8: {
						JSONArray jsonArray = jsonParserUtil.getJsonArraySon();

						if (jsonArray.length() > 0) {
							String[] names = new String[jsonArray.length() + 1];
							for (int i = 0; i < names.length - 1; i++) {
								names[i] = ((JSONObject) jsonArray.get(i))
										.getString("contactname");
							}
							if (!names[0].equals("") && names[0] != null) {
								ContactsInformationsData contactsInformationsData = new ContactsInformationsData();
								names[jsonArray.length()] = userSocketControl
										.getUserCenterData().getUsername();
								contactsInformationsData
										.addContactInformationsData(KaibesimcenterHelper
												.getInstance()
												.getContactsInformations(names));

								if (contactsInformationsData.toJSONArray() != null) {
									jsonParserUtil
											.newSelf(head, action)
											.putValue(
													"d",
													contactsInformationsData
															.toJSONArray())
											.commitNotJsonArraySon(
													userSocketControl
															.getClientStringWriter());
								} else {
									jsonParserUtil
											.newSelf(head, action)
											.putValue("d", new JSONObject())
											.commitNotJsonArraySon(
													userSocketControl
															.getClientStringWriter());
								}
							}
						}
					}
					break;

					case 9: {
						String username = (String) jsonParserUtil
								.getJsonObjectSonValue("username");
						String filename = (String) jsonParserUtil
								.getJsonObjectSonValue("filename");
						String filefolder = (String) jsonParserUtil
								.getJsonObjectSonValue("filefolder");
						Integer filesize = (Integer) jsonParserUtil
								.getJsonObjectSonValue("filesize");

						// 检查文件合法性，不带特殊符号等，这里先省略了，以后有时间再写个检查类

						boolean isExists = false;
						if (username.equals(userSocketControl
								.getUserCenterData().getUsername())) {
							isExists = StaticValuesUtil
									.isExistsUserFolder(filefolder);
						} else if (!(username.contains("/") || username
								.contains("."))) {
							isExists = StaticValuesUtil
									.isExistsContactFolder(filefolder);
						}

						if (filename.contains("..") || filename.contains("/")) {
							isExists = false;
						}

						if (filesize == null || filesize < 0) {
							isExists = false;
						}

						if (!isExists) {
							return errorConnection();
						}

						File file = new File(StaticValuesUtil.ROOTFILE_FILES
								+ File.separator + username + File.separator
								+ filefolder + File.separator + filename);

						if (filesize > file.length()) {
							return errorConnection();
						}

						jsonParserUtil
								.newSelf(head, action)
								.putJsonObjectSonValue("filename", filename)
								.putJsonObjectSonValue("targetSize",
										file.length())
								.commit(userSocketControl
										.getClientStringWriter());
						// ================================================

						int size = 0;
						if ((size = (int) (file.length() - filesize)) > 8100) {
							size = 8100;
						}
						byte[] bs = new byte[size];
						FileInputStream fis = null;

						try {
							fis = new FileInputStream(file);
							fis.skip(filesize);

							while (fis.read(bs) != -1) {
								jsonParserUtil
										.newSelf(
												filename,
												ByteStringUtil
														.bytes2StringBase64(bs))
										.commitNotJsonArraySon(
												userSocketControl
														.getClientStringWriter());

								if (fis.available() != 0
										&& fis.available() < bs.length) {
									bs = new byte[fis.available()];
								}
							}

							fis.close();
						} catch (FileNotFoundException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} catch (IOException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}

					}
					break;

					case 10: {
						final JSONObject jsonObject = jsonParserUtil
								.getJsonObjectSon();
						int i = KaibesimcenterHelper.getInstance()
								.updateUserInformation(
										userSocketControl.getUserCenterData()
												.getUsername(), jsonObject);
						// TODO
						final JSONArray keys = jsonObject.names();
						new DealWithContacts(userSocketControl) {

							@Override
							public void doWhat(ResultSet result) {
								UserSocketControl toClient = null;
								//
								try {
									if ((toClient = KaibesIMServer.mainClientControl
											.getMainSocketControl(result
													.getString("contactname"))) != null) {
										JsonParserUtil toFriend = new JsonParserUtil(1, 7);

										toFriend.putJsonObjectSonValue(
												"contactname",getUserSocketControl()
														.getUserCenterData().getUsername());
										for (int j = 0; j < keys.length(); j++) {
											toFriend.putJsonObjectSonValue(keys
													.getString(j), jsonObject
													.get(keys.getString(j)));
										}
										toFriend.commit(toClient
												.getClientStringWriter());
									}
								} catch (JSONException e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								} catch (SQLException e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								}
							}
						}.doit();

						if (i != 0) {
							jsonParserUtil.newSelf(head, action, "用户数据更新完成！")
									.commitNotJSONObjectSon(
											userSocketControl
													.getClientStringWriter());
						} else {
							jsonParserUtil.newSelf(head, action,
									"错误的数据请求，请不要恶意修改！").commitNotJSONObjectSon(
									userSocketControl.getClientStringWriter());
						}

					}
					break;

					case 11: {
						String contactname = (String) jsonParserUtil
								.getJsonObjectSonValue("contactname");
						String remark = (String) jsonParserUtil
								.getJsonObjectSonValue("remark");
						if (remark != null) {
							KaibesimcenterHelper.getInstance()
									.updateContactRemark(
											userSocketControl
													.getUserCenterData()
													.getUsername(),
											contactname, remark);
						}
						jsonParserUtil.newSelf(head, action, "修改好友备注完成！")
								.commitNotJSONObjectSon(
										userSocketControl
												.getClientStringWriter());
					}
					break;

					case 12: {
						String username = (String) jsonParserUtil
								.getJsonObjectSonValue("username");
						String contactname = (String) jsonParserUtil
								.getJsonObjectSonValue("contactname");
						String message = "用户" + username + "向你发了一个好友请求！";

						// notification所有者为联系人，而非用户
						KaibesimcenterHelper.getInstance().addNotification(
								contactname, username, 2, message);

						jsonParserUtil
								.newSelf(head, action)
								.putJsonObjectSonValue("message",
										"好友请求已发送，等待对方验证！")
								.commit(userSocketControl
										.getClientStringWriter());

						UserSocketControl toClient = null;
						if ((toClient = KaibesIMServer.mainClientControl
								.getMainSocketControl(contactname)) != null) {
							jsonParserUtil
									.newSelf(head,
											NotificationInterpreter.ACTION)
									.putJsonObjectSonValue(
											"id",
											KaibesimcenterHelper.getInstance()
													.getNotificationId(message))
									.putJsonObjectSonValue("contactname",
											username)
									.putJsonObjectSonValue("action", 2)
									.putJsonObjectSonValue("message", message)
									.commit(toClient.getClientStringWriter());
						}

					}
					break;
					case 13: {
						String username = userSocketControl.getUserCenterData()
								.getUsername();
						String contactname = (String) jsonParserUtil
								.getJsonObjectSonValue("contactname");

						KaibesimcenterHelper.getInstance().removeContact(
								username, contactname);
						KaibesimcenterHelper.getInstance().removeContact(
								contactname, username);

						jsonParserUtil
								.newSelf(head, action)
								.putJsonObjectSonValue("message", "好友删除成功！")
								.commit(userSocketControl
										.getClientStringWriter());

						UserSocketControl toClient = null;
						if ((toClient = KaibesIMServer.mainClientControl
								.getMainSocketControl(contactname)) != null) {
							jsonParserUtil
									.newSelf(head, action)
									.putJsonObjectSonValue("contactname",
											username)
									.commit(toClient.getClientStringWriter());
						}
					}
					break;
					case 14: {
						String username = (String) jsonParserUtil
								.getJsonObjectSonValue("username");
						ResultSet result = null;
						if (username.equals("")) {
							String nickname = StaticValuesUtil
									.changeStringForRegexp((String) jsonParserUtil
											.getJsonObjectSonValue("nickname"));
							String sex = StaticValuesUtil
									.changeSexForRegexp((String) jsonParserUtil
											.getJsonObjectSonValue("sex"));

							String birth_1 = StaticValuesUtil
									.changeBirthForRegexp_1((String) jsonParserUtil
											.getJsonObjectSonValue("birth_1"));
							String birth_2 = StaticValuesUtil
									.changeBirthForRegexp_2((String) jsonParserUtil
											.getJsonObjectSonValue("birth_2"));

							result = KaibesimcenterHelper.getInstance()
									.getContactsInformations(nickname, sex,
											birth_1, birth_2);

						} else {
							result = KaibesimcenterHelper.getInstance()
									.getUserInformationOther(username);

						}

						jsonParserUtil.newSelf(head, action);
						if (result != null) {

							try {
								while (result.next()) {
									JSONObject jsonObject = StaticValuesUtil
											.result2jsonObjecContact(result);
									jsonObject.put("remark", "");
									jsonObject
											.put("online",
													KaibesIMServer.mainClientControl
															.getMainSocketControl(username) == null ? false
															: true);

									jsonParserUtil
											.putJsonArraySonValue(jsonObject);
								}
							} catch (SQLException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}
						}
						jsonParserUtil.commitNotJSONObjectSon(userSocketControl
								.getClientStringWriter());

					}
					break;
					case 15: {
						String filename = (String) jsonParserUtil
								.getJsonObjectSonValue("filename");
						String filefolder = (String) jsonParserUtil
								.getJsonObjectSonValue("filefolder");
						int filesize = (int) jsonParserUtil
								.getJsonObjectSonValue("filesize");

						if (!StaticValuesUtil.isFilename(filename)) {
							return errorConnection();
						}

						if (!StaticValuesUtil.isExistsUserFolder(filefolder)) {
							return errorConnection();
						}

						File userFile = new File(userSocketControl
								.getUserFileFolder().getPath()
								+ File.separator
								+ filefolder + File.separator + filename);

						KaibesFile userFileCache = new KaibesFile(
								userSocketControl.getUserCacheFolder()
										.getPath()
										+ File.separator
										+ filefolder
										+ File.separator
										+ filename, filesize);

						userFileCache.setType(StaticValuesUtil
								.getType(filefolder));

						if (userFile.exists()
								|| userFileCache.length() >= filesize) {
							jsonParserUtil
									.newSelf(1, 15)
									.putJsonObjectSonValue("filename", filename)
									.putJsonObjectSonValue("message",
											"该文件已经存在！")
									.commit(userSocketControl
											.getClientStringWriter());
						} else {
							if (userSocketControl.getKaibesFilesUtil()
									.addKabesFile(userFileCache) == null) {
								jsonParserUtil
										.newSelf(1, 15)
										.putJsonObjectSonValue("filename",
												filename)
										.putJsonObjectSonValue("message",
												"您已经达到文件同时上传的最大数量！")
										.commit(userSocketControl
												.getClientStringWriter());
							} else {
								jsonParserUtil
										.newSelf(1, 15)
										.putJsonObjectSonValue("filename",
												filename)
										.putJsonObjectSonValue("filesize",
												userFileCache.length())
										.commit(userSocketControl
												.getClientStringWriter());
							}

						}

					}
					break;
					case 16: {
						NotificationInterpreter.explainServer(jsonParserUtil,
								userSocketControl);
					}
					break;
					case 17: {
						goInt = ClientStringReader.breakInt;
						userSocketControl.unLogin();
						userSocketControl.createThreadLogin(1);
					}
					break;

					case 99: {
						Set<String> keys = KaibesIMServer.mainClientControl
								.getMainSocketControls().keySet();
						String[] keyArr = new String[keys.size()];
						keys.toArray(keyArr);

						jsonParserUtil.newSelf(head, action);
						for (int i = 0; i < keyArr.length; i++) {
							jsonParserUtil
									.putJsonArraySonValue(new JSONObject().put(
											"contactname", keyArr[i]));
						}
						jsonParserUtil.commitNotJSONObjectSon(userSocketControl
								.getClientStringWriter());

					}
					break;
					default:
					break;
				}

			} else if (head == 0 && (jsonParserUtil.getValue("a") != null)
					&& jsonParserUtil.getValue("d") != null) {

				final String filename = (String) jsonParserUtil.getValue("a");
				String data = (String) jsonParserUtil.getValue("d");

				if (userSocketControl.getKaibesFilesUtil().hasKaibesFile(
						filename)) {

					userSocketControl.getKaibesFilesUtil()
							.getKaibesFile(filename).write2File(data);

					if (userSocketControl.getKaibesFilesUtil()
							.getKaibesFile(filename).isComplete()) {

						userSocketControl.getKaibesFilesUtil()
								.cacheRenameToFile(
										userSocketControl.getKaibesFilesUtil()
												.getKaibesFile(filename));

						uploadCallback(userSocketControl, userSocketControl
								.getKaibesFilesUtil().getKaibesFile(filename));

						userSocketControl.getKaibesFilesUtil()
								.removeKaibesFileNotClose(filename);

						jsonParserUtil
								.newSelf(1, 15)
								.putJsonObjectSonValue("filename", filename)
								.putJsonObjectSonValue("message", "文件上传完成！")
								.putJsonObjectSonValue("status", "")
								.commit(userSocketControl
										.getClientStringWriter());

						new DealWithContacts(userSocketControl) {

							@Override
							public void doWhat(ResultSet result) {
								UserSocketControl toClient = null;
								try {
									if ((toClient = KaibesIMServer.mainClientControl
											.getMainSocketControl(result
													.getString("contactname"))) != null) {

										JsonParserUtil toFriend = new JsonParserUtil(
												1, 7);

										toFriend.putJsonObjectSonValue(
												"contactname",
												getUserSocketControl()
														.getUserCenterData()
														.getUsername())
												.putJsonObjectSonValue("photo",
														filename)
												.commit(toClient
														.getClientStringWriter());
									}
								} catch (SQLException e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								}
							}
						}.doit();

					}
				} else {
					return errorConnection();
				}

			} else {
				return errorConnection();
			}
		} else {
			return errorConnection();
		}

		return goInt;
	}

	public static void uploadCallback(UserSocketControl userSocketControl,
			KaibesFile kaibesFile) {
		switch (kaibesFile.getType()) {
			case StaticValuesUtil.USER_PHOTO:
				KaibesimcenterHelper.getInstance().updateUserPhoto(
						userSocketControl.getUserCenterData().getUsername(),
						kaibesFile.getName());
			break;

			default:
			break;
		}
	}

	private static int errorConnection() {
		ServerMainView.serverPanelView.panel_login.addLog("发现非法链接，抛弃掉！");
		return ClientStringReader.stopInt;
	}

	public static boolean closeThread(UserSocketControl userSocketControl) {
		userSocketControl.removeCurrentThreadNum();
		return false;
	}

	public static boolean closeThreadSocket(UserSocketControl userSocketControl) {
		userSocketControl.closeThreadSocket();
		return false;
	}

	public static JsonParserUtil createFileJson(String filename, byte[] bs) {
		String data = ByteStringUtil.bytes2StringBase64(bs);
		return new JsonParserUtil(filename, data);
	}

	private static void setOnline(String contactname,
			UserSocketControl userSocketControl, JsonParserUtil jsonParserUtil) {
		boolean ifFriendOnline = false;

		UserSocketControl toClient = null;
		if ((toClient = KaibesIMServer.mainClientControl
				.getMainSocketControl(contactname)) != null) {
			ifFriendOnline = true;
			JsonParserUtil toFriend = new JsonParserUtil(1, 7);

			toFriend.putJsonObjectSonValue("contactname",
					userSocketControl.getUserCenterData().getUsername())
					.putJsonObjectSonValue("online", true)
					.commit(toClient.getClientStringWriter());
		}

		jsonParserUtil.newJsonObjectSon()
				.putJsonObjectSonValue("contactname", contactname)
				.putJsonObjectSonValue("online", ifFriendOnline)
				.addJSONObjectSon();
	}

}
